/*
 *  $Id: BlackWidow.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *  This file is a part of Ragima CCG.
 *  (C) 2008 Ragima development group.
 *
 *  Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Darkness.Creatures {
    public class BlackWidow: CreatureCard {
        public BlackWidow(): base("001_d_c_black_widow") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Darkness;
            Value = 100;
            Damage = 5;
            Health = 4;
            AddManaCost(ElementType.Darkness, 6);
        }
        public override void SetNaturalAffects(ICollector<Affect> affects) {
            affects.Add<Affects.Undead>();
            affects.Add(new Affects.OnDamage(DoDamage, AffectSummaryType.Local));
        }

        private static readonly Languages.CardPhrase<BlackWidow> OverDamage = new Languages.CardPhrase<BlackWidow>("over_damage");

        private static void DoDamage(AbstractObject target, DamageInfo damage) {
            Creature attacker;
            if (MeleeDamageInfo.TryGetAttacker(damage, out attacker))
                attacker.AddAffect(new Affects.Poison(2));
            if (damage.FullDamage > damage.HealthChange) {
                int dmg = damage.FullDamage - damage.HealthChange;
                Creature widow = target as Creature;
                Game.Current.Log.Add(OverDamage.Phrase, widow, dmg);
                DoVictim(widow, widow.NeighbourLeft, ref dmg);
                if (dmg >= 0) DoVictim(widow, widow.NeighbourRight, ref dmg);
                if (dmg < 0) widow.HealBy(new DamageInfo(DamageType.Health, -dmg));
            }
        }

        private static void DoVictim(Creature widow, Creature victim, ref int dmg) {
            if (victim == null && victim.Health > 0) return;
            dmg -= victim.Health;
            victim.InstantDeath();
        }
    }
}
